<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>1、笔试题</title>
</head>
<body>
    <script>
        var str = 'qweuyghjdsndzmcbkajdsfhwueyjhadfj';
        // 第一个不重复的字符
        function test(str){
            var temp = {};
            
            // 将所有的字符出现的次数按字母出现先后顺序排列
            for(var i = 0; i < str.length; i++){
                if(!temp.hasOwnProperty(str[i])){
                    temp[str[i]] = 1;
                } else {
                    temp[str[i]]++;
                }
            }

            // 找出第一个排列1次的字母
            for(var key in temp){
                if(temp[key] === 1){
                    return key;
                }
            }
        }

        var test = test(str);
        console.log(test);

        // 闭包测试题
        console.log('------分割线-----');

        function Test(a, b, c){
            var d = 0;
            this.a = a;
            this.b = b;
            this.c = c;

            function e(){
                d++;
                console.log(d);
            }

            this.f = e;
        }

        var test1 = new Test();
        test1.f();
        test1.f();
        var test2 = new Test();
        test2.f();

        console.log('------分割线-----');

        function test3(){
            console.log(typeof(arguments));
        }
        test3();

        console.log('------分割线-----');

        // 函数表达式忽略函数名
        var test = function a(){
            return 'a';
        }
        console.log(typeof(a));

        console.log('------分割线-----');
        function test4(day){
            // switch(day){
            //     case 1:
            //         console.log('Mon');
            //     break
            //     case 2:
            //         console.log('Tue');
            //     break
            //     case 3:
            //         console.log('Wed');
            //     break
            //     case 4:
            //         console.log('Thu');
            //     break
            //     case 5:
            //         console.log('Fri');
            //     break
            //     case 6:
            //         console.log('Sat');
            //     break
            //     case 7:
            //         console.log('Sun');
            //     break
            //     default:
            //         console.log("I don't know");
            // }
            
            // 优化
            var weekArr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
            weekArr[day - 1] !== undefined ? 
                                            console.log(weekArr[day - 1])
                                            : 
                                            console.log("I don't know");
        }
        test4(1);

    </script>
</body>
</html>